import random

icbcbank = {
    'name': '中国工商银行昌平支行',
    12345678: {
        'name': '王一',
        'password': 123456,
        'address': {'国家': '中国', '省份': '河南省', '街道': '五六二街道', '门牌号': '156号'},
        'money': 3000,
        'bankname': '中国工商银行昌平支行'
    },
    12345679: {
        'name': '王二',
        'password': 123456,
        'address': {'国家': '中国', '省份': '河南省', '街道': '五六二街道', '门牌号': '156号'},
        'money': 3000,
        'bankname': '中国工商银行昌平支行'
    },
    12345610: {
        'name': '王三',
        'password': 123456,
        'address': {'国家': '中国', '省份': '河南省', '街道': '五六二街道', '门牌号': '156号'},
        'money': 3000,
        'bankname': '中国工商银行昌平支行'
    },
}


class Icbcbank():
    def __init__(self, icbcbank):
        self.icbcbank = icbcbank

    def adduser(self, user):  #####添加账号
        k = 0
        for i in self.icbcbank.keys():
            k += 1
        if k > 100:
            print('用户仓库已满')
            return 3
        r = random.randint(10000000, 99999999)
        if r not in self.icbcbank.keys():
            self.icbcbank[r] = user
            self.icbcbank[r]['bankname'] = '中国工商银行昌平支行'
            print('添加成功')
            return 1
        else:
            return 2

    def save(self, account, money):  # 存钱
        if account not in self.icbcbank.keys():
            print('账号不存在')
            return False
        else:
            self.icbcbank[account]['money'] += money
            print('存取成功')
            return 0

    def draw(self, account, password, money):  # 取钱
        if account not in self.icbcbank.keys():
            print('账号不存在')
            return 1
        elif password != self.icbcbank[account]['password']:
            print('密码错误')
            return 2
        elif money > self.icbcbank[account]['money']:
            print('余额不足')
            return 3
        else:
            self.icbcbank[account]['money'] -= money
            print('取款成功')
            return 0

    def transfers(self, maccount, faccount, password, money):  # 转账
        if maccount and faccount not in self.icbcbank.keys():
            print('账号不存在')
            return 1
        elif password != self.icbcbank[maccount]['password']:
            print('密码错误')
            return 2
        elif money > self.icbcbank[maccount]['money']:
            print('余额不足')
            return 3
        else:
            self.icbcbank[maccount]['money'] -= money
            self.icbcbank[faccount]['money'] += money
            return 0

    def query(self, account, password):  # 查询
        if account not in self.icbcbank.keys():
            print('用户不存在！')
            return 1
        elif password != self.icbcbank[account]['password']:
            print('密码错误！')
            return 2
        else:
            print('当前账号:{},密码:{},余额:{},用户居住地址:{}{}{}{},当前账号开户行:{}'.format(
                account, password, self.icbcbank[account]['money'], self.icbcbank[account]['address']['国家']
                , self.icbcbank[account]['address']['省份'], self.icbcbank[account]['address']['街道'],
                self.icbcbank[account]['address']['门牌号'], self.icbcbank[account]['bankname']
            ))


icbccp = Icbcbank(icbcbank)
# p=icbccp.adduser(   {
#          'name':'王五',
#          'password':123456,
#          'address': {'国家':'中国','省份':'河南省','街道':'五六二街道','门牌号':'156号'},
#          'money':3000,
#          'bankname':'中国工商银行昌平支行'
#          })
# print(p)

# print(icbccp.save(9999999999,1000))
# print(icbccp.save(12345610,500))
# print(icbccp.icbcbank)

# print(icbccp.draw(99999999,7788,10000))             ###账户不存在返回1
# print(icbccp.draw(12345678,6666,100))               ####密码错误返回2
# print(icbccp.draw(12345678,123456,10000))           ###余额不足返回3
# print(icbccp.draw(12345678,123456,100))             ###取钱成功返回0


# print(icbccp.transfers(12345678,11111111,123456,500))       ###账户不存在返回1
# print(icbccp.transfers(12345678,12345679,122222,500))       ###密码错误返回2
# print(icbccp.transfers(12345678,12345679,123456,5000))      ###余额不足返回3
# print(icbccp.transfers(12345678,12345679,123456,500))       ###转账成功返回0
# print(icbccp.icbcbank)


# icbccp.query(12345678,123456)


while 1:
    print("*" * 20)
    print("中国工商银行账户管理系统")
    print("*" * 20)
    print()
    print('*1.开户')
    print('*2.存钱')
    print('*3.取钱')
    print('*4.转账')
    print('*5.查询')
    print('*6.Bye')
    print("*" * 20)
    p = input('请选择要进行的操作')
    if p == '6':
        print('欢迎下次光临！')
        break
    elif p == '1':
        u = icbccp.adduser({
            'name': '王五',
            'password': 123456,
            'address': {'国家': '中国', '省份': '河南省', '街道': '五六二街道', '门牌号': '156号'},
            'money': 3000,
            'bankname': '中国工商银行昌平支行'
        })
    elif p == '2':
        print(icbccp.save(9999999999, 1000))        ###账户不存在返回false
        print(icbccp.save(12345610, 500))           ##存取成功
        print(icbccp.icbcbank)
    elif p == '3':
        print(icbccp.draw(99999999, 7788, 10000))  ###账户不存在返回1
        print(icbccp.draw(12345678, 6666, 100))  ####密码错误返回2
        print(icbccp.draw(12345678, 123456, 10000))  ###余额不足返回3
        print(icbccp.draw(12345678, 123456, 100))  ###取钱成功返回0
    elif p == '4':
        print(icbccp.transfers(12345678, 11111111, 123456, 500))  ###账户不存在返回1
        print(icbccp.transfers(12345678, 12345679, 122222, 500))  ###密码错误返回2
        print(icbccp.transfers(12345678, 12345679, 123456, 5000))  ###余额不足返回3
        print(icbccp.transfers(12345678, 12345679, 123456, 500))  ###转账成功返回0
        # print(icbccp.icbcbank
    elif p == '5':
        icbccp.query(12345677,123456)  ###账户不存在
        icbccp.query(12345678,111111)  ###密码错误
        icbccp.query(12345678, 123456)  ##查询成功
    else:
        print("没这个选项")
